<?php 
class ControllerInformationInformationList extends Controller {
	public function index() {
		$this->language->load('information/information');

		$this->load->model('catalog/information_list');

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);
		$this->data['breadcrumbs'][] = array(
			'text'      => '最新资讯',
			'href'      => $this->url->link('information/information_list'),
			'separator' => $this->language->get('text_separator')
		);

		if (isset($this->request->get['sort'])) {
		     $sort = $this->request->get['sort'];
		} else {
			$sort = 'id.title';
		}

		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'ASC';
		}

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}

		$url = '';

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['order'])) {
			$url .= '&order=' . $this->request->get['order'];
		}

		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}
		
		$default_limit=$this->config->get('config_category_limit');
		
		$this->data['informations'] = array();

		$data = array(
			'sort'  => $sort,
			'order' => $order,
			'start' => ($page - 1) * $default_limit,
			'limit' => $default_limit
		);

		$information_total = $this->model_catalog_information_list->getTotalInformations();

		$results = $this->model_catalog_information_list->getInformations($data);

		foreach ($results as $result) {

			$this->data['informations'][] = array(
				'information_id' => $result['information_id'],
				'title'          => $result['title'],
				'create_date'    => $result['create_date'],
				'href'           => $this->url->link('information_id=' . $result['information_id'])
			);
		}	
		
		$pagination = new Pagination();
		$pagination->total = $information_total;
		$pagination->page = $page;
		$pagination->limit = $default_limit;
//		$pagination->limit = 1;
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('information/information_list',$url . '&page={page}', 'SSL');

		$this->data['pagination'] = $pagination->render();

		$this->data['sort'] = $sort;
		$this->data['order'] = $order;
		$this->data['limit'] = $default_limit;
//		$this->data['limit']=1;
		
		

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/information_list.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/information/information_list.tpl';
		} else {
			$this->template = 'default/template/information/information_list.tpl';
		}

		$this->children = array(
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'
		);

		$this->response->setOutput($this->render());
		
	}
	
}
?>